package edu.taru.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;

import util.RowHandlerMappers;
import util.SqlHelper;

public class SearchDaoImpl {
	public Vector<Vector<String>> select(String username){
		String sql ="select u.*,d.department_name from user u left join department d on d.department_id = u.department_id where username like '%"+username+"%'";
		
		Vector<Vector<String>> vectors = new Vector<Vector<String>>();
		SqlHelper.select(sql, new RowHandlerMappers() {
			
			@Override
			public Vector<String> mapping(ResultSet rs) {

				Vector<String> vector=null;
				try {
					while(rs.next()) {
						vector = new Vector<String>();
						vector.add(rs.getString("id"));
						vector.add(rs.getString("username"));
						vector.add(rs.getString("password"));
						vector.add(rs.getString("sex"));
						vector.add(rs.getString("city"));
						vector.add(rs.getString("email"));
						vector.add(rs.getString("birthday"));
						vector.add(rs.getString("name"));
						vector.add(rs.getString("department_id"));
						vector.add(rs.getString("department_name"));
						vectors.add(vector);
					}
					
				} catch (SQLException e) {
					e.printStackTrace();
				}
				return  vector;
			}
		});
		return vectors;
	}

}
